package com.demo.controller;


import com.demo.entity.User;
import com.demo.entity.base.Result;
import com.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Ymj
 * @since 2020-11-23
 */
@RestController
@CrossOrigin
@RequestMapping("/demo/user")
public class UserController extends BaseController<User, UserService> {

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
        this.manager = this.userService;
    }

    @GetMapping("/login")
    public Result login(String username, String password) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        int i = userService.login(user);
        //0:账户不存在 1:登录成功 2:密码错误
        if (i == 0) return Result.error("账户不存在");
        if (i == 1) return Result.success();
        if (i == 2) return Result.error("密码错误");
        return Result.success();
    }
    @GetMapping("/updatePassword")
    public Result updatePassword( User user) {
        userService.updatePassword(user);
        return Result.success();
    }
    @GetMapping("/updateUser")
    public Result updateUser() {
        userService.updateUser();
        return Result.success();
    }
}

